package oppsa.controller;

import java.util.Locale;
import java.util.ResourceBundle;

import oppsa.util.Constants;
 
public class Translate
{
	public final Locale ENGLISH_LANGUAGE;
	public final Locale FRENCH_LANGUAGE;
 
	private final String[] languagesList;
 
	private Locale currentLanguage;
 
	private ResourceBundle MyResources;
 
	private String currentLanguageString;

	public Translate()
	{
		languagesList=new String[]
		{
			"Francais",
			"English"
		};
		ENGLISH_LANGUAGE=new Locale("en","US");
		FRENCH_LANGUAGE=new Locale("fr","FR");
 
		Properties prop = new Properties();
		prop.loadProperties(Constants.config_path);
		currentLanguageString = prop.getProperties().getProperty("Language");
		
		boolean change=false;
		if(currentLanguageString.equals("French"))
		{
			currentLanguage=FRENCH_LANGUAGE;
			currentLanguageString="French";
			change=true;
		}
		else if (currentLanguageString.equals("English"))
		{
			currentLanguage=ENGLISH_LANGUAGE;
			currentLanguageString="English";
			change=true;
		}
 
		if(change)
		{
			MyResources=ResourceBundle.getBundle("MyResources",currentLanguage);
		}
	}

	public String[] getLanguagesList()
	{
		return languagesList;
	}

	public String getLocalizedText(String text)
	{
		String ret = MyResources.getString(text);
		return ret;
	}
 
	public void setCurrentLanguage(final String newLanguage)
	{
		boolean change=false;
		if(currentLanguageString.equals("French"))
		{
			currentLanguage=FRENCH_LANGUAGE;
			currentLanguageString="French";
			change=true;
		}
		else if (currentLanguageString.equals("English"))
		{
			currentLanguage=ENGLISH_LANGUAGE;
			currentLanguageString="English";
			change=true;
		}
 
		if(change)
		{
			MyResources=ResourceBundle.getBundle("MyResources",currentLanguage);
		}
	} 

	public Locale getCurrentLanguage()
	{
		return currentLanguage;
	}
 
	public String getCurrentLanguageString()
	{
		return currentLanguageString;
	}
}